package com.xinhua.erp.service;

import com.xinhua.erp.pojo.Result;
import com.xinhua.erp.pojo.Role;
import com.xinhua.erp.pojo.User;
import com.xinhua.erp.repo.UserRepo;
import com.xinhua.erp.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @ClassName UserService
 * @Description TODO
 * @Date 2020/1/1 下午2:05
 * @Version 1.0
 **/
@Service
@Transactional
public class UserService {
    @Autowired
    private UserRepo userRepo;

    @Autowired
    private IdWorker idWorker;

    public Result findById(long id){

        return Result.OK(userRepo.getOne(id));

    }

    public Result findAll(){

        List<User> list=userRepo.findAll();

        return Result.OK(list);

    }

    public Result deleteById(long id){

        userRepo.deleteById(id);

        return Result.OK();

    }

    public Result save(User user){

        user.setId(idWorker.nextId());

        userRepo.save(user);

        return Result.OK();

    }

    public Result update(User user){

        userRepo.save(user);

        return Result.OK();

    }
}
